package com.googlecode.alfrescocachingserver.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class WebHelper
{
    public static void updateHeaderMap(Map<String, List<Object>> headerMap, String name, Object value, boolean replace)
    {
        if (StringUtils.isBlank(name) || value == null)
        {
            return;
        }

        List<Object> headerValues = headerMap.get(name);

        if (headerValues == null)
        {
            headerValues = new ArrayList<Object>();
            headerMap.put(name, headerValues);
        }
        else if (replace)
        {
            headerValues.clear();
        }

        headerValues.add(value);
    }
}
